﻿<%@ Page Title="" Language="C#" MasterPageFile="~/site.Master" AutoEventWireup="true" CodeBehind="SanPham.aspx.cs" Inherits="WebComputers.SanPham" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Middle_Content" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main_Content" runat="server">
    <asp:Repeater runat="server" ID="rptTenLoai" OnItemDataBound="rptTenLoai_ItemDataBound">
        <ItemTemplate>
            <h1>
                <a href="DanhMucSanPham.aspx?id=<%# Eval("iLoaiHangHoa_ID") %>"><%# Eval("sTenLoai") %></a>
            </h1>
            <asp:Repeater runat="server" ID="rptSanPhamCon">
                <ItemTemplate>
                    <div <%# ((Container.ItemIndex+1) % 3) == 0 ? "class='product_box no_margin_right'" : "class='product_box'" %>>
                        <a class="noClass1" href="ChiTietSanPham.aspx?id=<%# Eval("iDanhMucHangHoa_ID") %>">
                            <img src="<%# FillImage(Eval("sHinhDaiDien").ToString()) %>" alt="" style="width: 200px; height: 150px;" />
                        </a>
                        <h3><%# Eval("sTenHangHoa") %></h3>
                        <p class="product_price"><%# string.Format("{0:n0}",Eval("dGiaBan")) %> VNĐ</p>
                        <a class="add_to_cart" onclick="AddToCart(<%# Eval("iDanhMucHangHoa_ID") %>)">Thêm vào giỏ</a>
                        <a class="detail" href="ChiTietSanPham.aspx?id=<%# Eval("iDanhMucHangHoa_ID") %>">Chi tiết</a>
                    </div>
                </ItemTemplate>
            </asp:Repeater>
            <div class="cleaner"></div>
        </ItemTemplate>
    </asp:Repeater>
    <script>
        function AddToCart(id) {
            $.ajax({
                type: "POST",
                url: "SanPham.aspx/AddToCart",
                data: "{id: " + id + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: ReloadCart,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }
        
        function ReloadCart(response) {
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            $("#lblSlg").html(xml.find("TongSoLuong"));                        
            $("#lblTTien").html(xml.find("TongTien"));            
        }
    </script>
</asp:Content>
